﻿using Microsoft.Extensions.Configuration;
using Org.Apache.Rocketmq;

namespace rocketmq.test
{
    public class RocketMQHelper
    {
        public static ClientConfig GetRocketMQClientConfig()
        {
            var config = new ConfigurationBuilder().AddUserSecrets<Program>().Build();
            config.GetValue<string>("accessKey");

            var accessKey = config.GetValue<string>("accessKey");
            var secretKey = config.GetValue<string>("secretKey");

            var credentialsProvider = new StaticSessionCredentialsProvider(accessKey, secretKey);
            var endpoints = config.GetValue<string>("endpoints");
            var clientConfig = new ClientConfig.Builder()
                .SetEndpoints(endpoints)
                .SetCredentialsProvider(credentialsProvider)
                .Build();
            return clientConfig;
        }

        public static Dictionary<string, FilterExpression> GetSubscription(string topic)
        {
            return new Dictionary<string, FilterExpression>
                { { topic, new FilterExpression("*") } };
        }

    }
}
